﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace GraphDrawing.Graph.Model
{
    /// <summary>
    /// Фабрика графических путей для линий определённой формы.
    /// </summary>
    public static class GraphicsPathFactory
    {
        /// <summary>
        /// Создаёт путь для линии заданного типа.
        /// </summary>
        /// <param name="shape">Тип линии.</param>
        /// <param name="p1">Начальная точка.</param>
        /// <param name="p2">Конечная точка.</param>
        public static GraphicsPath CreatePath(LineShapeType shape, Point p1, Point p2)
        {
            var path = new GraphicsPath();
            switch (shape)
            {
                case LineShapeType.DIRECT:
                    path.AddLine(p1, p2);
                    break;
                case LineShapeType.BEZIER:
                    var x = p1.X + (p2.X - p1.X)/2;
                    var cp1 = new Point(x, p1.Y);
                    var cp2 = new Point(x, p2.Y);
                    path.AddBezier(p1, cp1, cp2, p2);
                    break;
                default:
                    throw new NotImplementedException();
            }
            return path;
        }
    }
}